package org.cdivtc.exam.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("统一JSON返回格式")
public class JsonResult<T> {
    @ApiModelProperty(value = "状态码", example = "200")
    private int code;

    @ApiModelProperty(value = "返回消息", example = "操作成功")
    private String message;

    @ApiModelProperty("返回数据")
    private T data;

    public static <T> JsonResult<T> success() {
        return new JsonResult<>(200, "success", null);
    }

    public static <T> JsonResult<T> success(T data) {
        return new JsonResult<>(200, "success", data);
    }

    public static <T> JsonResult<T> fail(int code, String message) {
        return new JsonResult<>(code, message, null);
    }
}
